#include "networkjsonlistresponse.h"

namespace Network {

JSONListResponse::JSONListResponse(QObject *parent) :
    Network::JSONResponse(parent)
{
}


void JSONListResponse::parse(const QVariant &data)
{
    if (data.type() != QVariant::Map) {
        setError(Network::Response::Property, QString("The \"data\" field isn't compatible"));
        return;
    }

    QVariantMap map = data.toMap();

    /*
    if (!map.contains("tot")) {
        setError(Network::Response::Property, QString("The \"tot\" field is missing"));
        return;
    }

    QVariant total = map.value("tot");
    if (total.type() != QVariant::Int) {
        setError(Network::Response::Property, QString("The \"tot\" field isn't compatible"));
        return;
    }
    */

    if (!map.contains("list")) {
        setError(Network::Response::Property, QString("The \"list\" field is missing"));
        return;
    }

    QVariant list = map.value("list");
    if (list.type() != QVariant::List) {
        setError(Network::Response::Property, QString("The \"list\" field isn't compatible"));
        return;
    }

    parse(list.toList());
}

} // namespace Network
